<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Route_register
{
    private $_route_map = array(
        'get'    => array(),
        'post'   => array(),
        'put'    => array(),
        'delete' => array(),
    );
    
    public function attach($method, Array $params)
    {
        if (count($params) !== 2 OR
            ! is_string($params[0]) OR
            ! in_array($method, array('get', 'post', 'put', 'delete')))
        {
            return;
        }
        
        $reg = '/\{\w+?\}/';
        $replacement = '([\w\d]+?)';
        $params[0] = trim($params[0], '/');
        $route = preg_replace($reg, $replacement, $params[0]);
        $route_reg = '/^\/?'.str_replace(array('/', '-', '.'), array('\/', '\-', '\.'), $route).'\/?$/';
        
        $this->_route_map[$method][$route_reg] = $params[1];
    }
    
    public function get_route_map()
    {
        return $this->_route_map;
    }
}